package org.dromara.system.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.system.domain.Sms;
import org.dromara.system.domain.SmsCode;
import org.dromara.system.service.SmsService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 短信模块
 * 请先阅读文档 否则无法使用
 *
 * @author Lion Li
 * @version 4.2.0
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/sms")
public class SmsController {


    private final SmsService smsService;


    @SaIgnore
    @PostMapping(value = "/codes")
//    @SaCheckPermission("system:sms:codes")
    @Log(title = "用户短信", businessType = BusinessType.INSERT)
    public R<SmsCode> sendSmsCode(@RequestBody Sms sms) {
        SmsCode smsCode = smsService.generateCode(sms);
        return R.ok(smsCode);
    }

    @GetMapping(value = "/check")
    public String matchCodeAndGetPhone(String key, String code, Boolean delete, Integer second) {
        return smsService.matchCodeAndGetPhone(key, code, delete, second);
    }

}
